package com.example.bilibili.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.bilibili.domain.BiliAuditor;
import com.example.bilibili.domain.BiliUser;
import com.example.bilibili.mapper.BiliAuditorMapper;
import com.example.bilibili.mapper.BiliUserMapper;
import com.example.bilibili.service.BiliAuditorService;
import com.example.bilibili.service.BiliUserService;
import com.example.bilibili.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class AuditorController {
    @Autowired
    private BiliAuditorService biliAuditorService;
    @RequestMapping("/adminlogin")
    public int login(String audname,String password)   {


        QueryWrapper qw= new QueryWrapper();
        qw.select();
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("auditorName", audname);
        paramsMap.put("password", password);

        qw.allEq(paramsMap);
        BiliAuditor aud = biliAuditorService.getOne(qw);
        if(aud==null)
        {
            return  0;
        }
        return aud.getAuditorrole();
    }

    @RequestMapping("/findAll3Aud")
    public Object findAll3Aud(){
        QueryWrapper<BiliAuditor> qw= new QueryWrapper<>();
        qw.select("auditorId","auditorName","auditorAuthor","phone","gender","auditorRole").eq("auditorRole",3);
        return biliAuditorService.list(qw);
    }

    @RequestMapping("/findAll4Aud")
    public Object findAll4Aud(){
        QueryWrapper<BiliAuditor> qw= new QueryWrapper<>();
        qw.select("auditorId","auditorName","auditorAuthor","phone","gender","auditorRole").eq("auditorRole",4);
        return biliAuditorService.list(qw);
    }

   @RequestMapping("/findAudByname")
    public Object findAudByname(String audname){
        QueryWrapper qw= new QueryWrapper();
        qw.select("auditorId","auditorName","auditorAuthor","phone","gender","auditorRole").like("auditorName",audname);
        return biliAuditorService.list(qw);
    }

    @RequestMapping("/updateAud")
    public int UpdateUser(Integer audid,String audname,String phone,Integer gender){
        UpdateWrapper qw= new UpdateWrapper();
        qw.eq("auditorId",audid);
        BiliAuditor aud= biliAuditorService.getOne(qw);
        aud.setAuditorauthor(audname);
        aud.setPhone(phone);
        aud.setGender(gender);
        return biliAuditorService.update(aud,qw)?1:0;

    }

    @RequestMapping("/deleteAud")
    public int deleteAud(Integer audid) {
        QueryWrapper qw0= new QueryWrapper();
        qw0.eq("auditorId",audid);
        BiliAuditor aud=biliAuditorService.getOne(qw0);
        if(aud==null)
            return 0;
     biliAuditorService.removeById(audid);
     return  1;
    }



    }




